package one.stand.service.impl;

import lombok.extern.slf4j.Slf4j;
import one.stand.advice.ResultEnum;
import one.stand.mapper.UserSignMapper;
import one.stand.model.UserSign;
import one.stand.service.UserSignService;
import one.stand.util.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class UserSignServiceImpl implements UserSignService {
    @Autowired
    private UserSignMapper userSignMapper;

    @Override
    @Transactional
    public void save(Integer userId, String area, String build, String street, String num, String position) {
        AssertUtil.nonNull(userId, ResultEnum.NO_PARAM);
        AssertUtil.nonNull(area, ResultEnum.NO_PARAM);
        AssertUtil.nonNull(build, ResultEnum.NO_PARAM);
        AssertUtil.nonNull(street, ResultEnum.NO_PARAM);
        AssertUtil.nonNull(num, ResultEnum.NO_PARAM);
        AssertUtil.nonNull(position, ResultEnum.NO_PARAM);
        UserSign model = new UserSign();
        model.setUserId(userId);
        model.setArea(area);
        model.setBuild(build);
        model.setStreet(street);
        model.setNum(num);
        model.setPosition(position);
        model.setCreateTime(new Date());
        userSignMapper.insertSelective(model);
    }

    @Override
    public Integer checkSignByUserId(Integer userId) {
        return userSignMapper.checkSignByUserId(userId);
    }

    @Override
    public List<UserSign> userSignList() {
        return userSignMapper.userSignTop50List();
    }


}
